package com.ccdc.cbpc.bigdata.open.common.exception;


import com.ccdc.cbpc.bigdata.open.common.enums.RespCodeEnum;

/**
 * 系统异常
 * @author dong.zhang8
 * @date 2021-07-15
 */

public class BusinessException extends RuntimeException{

    private int errorCode;
    private String errorMsg;


    public BusinessException(){
        this(RespCodeEnum.SERVER_ERROR);
    }
    public BusinessException(RespCodeEnum respCodeEnum) {
        this(respCodeEnum,respCodeEnum.getDesc());
    }

    public BusinessException(RespCodeEnum respCodeEnum, String errorMsg) {
        super(errorMsg);
        this.errorCode = respCodeEnum.getCode();
        this.errorMsg = errorMsg;
    }

    public BusinessException(String errorMsg) {
        this(RespCodeEnum.SERVER_ERROR,errorMsg);
    }
    @Override
    public String getMessage() {
        if (this.errorMsg != null && !"".equals(this.errorMsg)) {
            return this.errorMsg;
        }
        return super.getMessage();
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    /**
     * 预定义异常信息
     */
    public static final BusinessException PARAM_ERROR = new BusinessException(RespCodeEnum.NOT_ALLOWED,"请检查参数");
}
